package ch7;

import java.util.Arrays;

public class ArrayFill {

	public static void main(String[] args) {
		int[][] arr = { { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 0 } };
		// 统计行列中是否有1
		boolean row[] = new boolean[arr.length];
		boolean col[] = new boolean[arr[0].length];
		for (int i = 0; i < arr.length; i++) {
			for (int j = 0; j < arr[i].length; j++) {
				if (arr[i][j] == 1) {
					row[i] = true;
					col[j] = true;
				}
			}
		}
		for (int i = 0; i < row.length; i++) {
			if (row[i]) {
				for (int j = 0; j < arr[i].length; j++) {
					arr[i][j] = 1;
				}
			}
		}
		for (int i = 0; i < col.length; i++) {
			if (col[i]) {
				for (int j = 0; j < arr.length; j++) {
					arr[j][i] = 1;
				}
			}
		}
		for (int i = 0; i < arr.length; i++) {
			System.out.println(Arrays.toString(arr[i]));
		}
	}

}
